﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "GmFamilyService.h"
#include "IFamilyGeneralForm.h"


namespace gfam
{

    class IFamily2DSketchCurve;
    class IFamily2DSketchLine;

    ///\brief 拉伸体错误类型
    enum class FamilyExtrusionErrorType : uint32_t
    {
        Valid = 0,                  ///< 轮廓没有错误
        NoSketch = 1,               ///< 没有草图平面
        EmptyProfile = 2,           ///< 轮廓线为空
        NotClosed = 3,              ///< 轮廓线不封闭
        NotStraight = 4,            ///< 顶面或底面定位线不平行于轮廓草图平面
        ZeroHeight = 5,             ///< 拉伸体高度为0
        Intersect = 6,              ///< 环相交
        SelfIntersect = 7,          ///< 环自交
        ProfileFamilyIllegal = 8,   ///< 轮廓族非法
        BothExist = 9               ///< 轮廓族与草图线同时存在
    };

    /// \brief 拉伸体
    class GM_FAMILY_SERVICE_EXPORT IFamilyExtrusion : public IFamilyGeneralForm
    {
        DEFINE_CAST_DERIVED(gfam::IFamilyExtrusion, gfam::IFamilyGeneralForm)

    public:

        /// \brief 创建拉伸体
        /// 
        /// \param pDocument 文档
        /// \param sketchId 草图id
        /// \param startOffset 起始高度
        /// \param endOffset 终止高度
        /// \return 拉伸体
        static IFamilyExtrusion* Create(gcmp::IDocument* pDocument, const gcmp::ElementId& sketchId, double startOffset, double endOffset);
        
        /// \brief 创建拉伸体
        /// 
        /// \param pDocument 文档
        /// \param sketchId 草图id
        /// \param endFaceSketchId 端面草图id
        /// \param startOffset 起始高度
        /// \param endOffset 终止高度
        /// \return 拉伸体
        static IFamilyExtrusion* Create(gcmp::IDocument* pDocument, const gcmp::ElementId& sketchId, const gcmp::ElementId& endFaceSketchId, double startOffset, double endOffset);

        /// \brief 获取起始高度
        /// 
        /// \return 起始高度
        virtual double GetStartOffset() const = 0;

        /// \brief 设置起始高度
        /// 
        /// \param  startOffset 起始高度值
        /// \return 设置成功返回true，失败返回false
        virtual bool SetStartOffset(double startOffset) = 0;

        ///\brief 获取终止高度
        /// 
        /// \return 终止高度
        virtual double GetEndOffset() const = 0;

        /// \brief 设置终止高度
        /// 
        /// \param  endOffset 终止高度值
        /// \return 设置成功返回true，失败返回false
        virtual bool SetEndOffset(double endOffset) = 0;

        /// \brief 获取轮廓草图
        /// 
        /// \return 轮廓草图
        virtual IFamilySketch2D*  GetProfileSketch() = 0;

        /// \brief 获取轮廓草图
        /// 
        /// \return 轮廓草图
        virtual const IFamilySketch2D*  GetProfileSketch() const = 0; 

        /// \brief 获取轮廓草图id
        /// 
        /// \return 轮廓草图id
        virtual gcmp::ElementId GetProfileSketchId() const = 0;

        /// \brief 获取端面草图id
        /// 
        /// \return 端面草图id
        virtual gcmp::ElementId GetEndfaceSketchId() const = 0;

        /// \brief 获取端面草图
        /// 
        /// \return 端面草图
        virtual IFamilySketch2D*  GetEndfaceSketch() = 0;

        /// \brief 获取端面草图
        /// 
        /// \return 端面草图
        virtual const IFamilySketch2D*  GetEndfaceSketch() const = 0;

        ///\brief 获取底面定位线
        /// 
        /// \return 底面定位线
        virtual const IFamily2DSketchLine* GetBottomLocationLine() const = 0;

        /// \brief 获取顶面定位线
        /// 
        /// \return 顶面定位线
        virtual const IFamily2DSketchLine* GetTopLocationLine() const = 0;


        /// \brief 检查数据是否合法
        /// 
        /// \param errorCurves  如果数据不合法，errorCurves保存出错的草图线
        /// \return 检查结果
        virtual FamilyExtrusionErrorType CheckDataIsValidDetailed(std::vector<IFamilySketchCurve*>& errorCurves) const = 0;

        // 是否是拉伸体的端面（顶面或底面）
        virtual bool IsEndFace(const gcmp::IGraphicsNodeReference& nodeReference) const = 0;

        /// \brief 设置轮廓族实例id
        /// 
        /// \param id  轮廓族实例id
        /// \return 设置成功返回true,否则返回false
        virtual bool SetInstanceIdOfProfileFamily(const gcmp::ElementId& id) = 0;

        /// \brief 获取轮廓族实例id
        /// 
        /// \return 轮廓族实例id
        virtual gcmp::ElementId GetInstanceIdOfProfileFamily() const = 0;

        /// \brief 获取轮廓族实例
        /// 
        /// \return 轮廓族实例
       virtual gcmp::IElement*  GetProfileFamilyInstance() =0;

       /// \brief 获取轮廓族实例
       /// 
       /// \return 轮廓族实例
       virtual const gcmp::IElement* GetProfileFamilyInstance()const =0;

    public:
        /// \brief 顶面定位线名称
        static std::wstring TopLocationLineName;

        /// \brief 底面定位线名称
        static std::wstring BottomLocationLineName;

    };

} 